from pydantic import BaseModel


class OcbStates(BaseModel):
    link_0_ocb: bool = False
    link_1_ocb: bool = False
    service_0_ocb: bool = False
    service_1_ocb: bool = False
    service_2_ocb: bool = False
    service_3_ocb: bool = False
    service_5v_ocb: bool = False

    def get(self, name: str) -> bool:
        return getattr(self, name)

    def set(self, name: str, state: bool):
        return setattr(self, name, state)


class OcbStatesInfo(BaseModel):
    class Info(BaseModel):
        address: int = 0x0000_0000
        offset: int = 0x00

    link_0_ocb: Info = Info(address=0x83CE_0020, offset=0x00)
    link_1_ocb: Info = Info(address=0x83CE_0020, offset=0x01)
    service_0_ocb: Info = Info(address=0x83CE_0020, offset=0x03)
    service_1_ocb: Info = Info(address=0x83CE_0020, offset=0x02)
    service_2_ocb: Info = Info(address=0x83CE_0020, offset=0x05)
    service_3_ocb: Info = Info(address=0x83CE_0020, offset=0x04)
    service_5v_ocb: Info = Info(address=0x83CE_0020, offset=0x06)

    def get(self, name: str) -> Info:
        return getattr(self, name)


class OcbCurrents28v(BaseModel):
    link_0_ocb: float = 0.0
    link_1_ocb: float = 0.0
    service_0_ocb: float = 0.0
    service_1_ocb: float = 0.0
    service_2_ocb: float = 0.0
    service_3_ocb: float = 0.0
    service_5v_ocb: float = 0.0

    def get(self, name: str) -> float:
        return getattr(self, name)

    def set(self, name: str, value: float):
        return setattr(self, name, value)


class OcbCurrents28vInfo(BaseModel):
    class Info(BaseModel):
        address: int = 0x0000_0000
        offset: int = 0x00

    link_0_ocb: Info = Info(address=0x83CE_0000, offset=0x24)
    link_1_ocb: Info = Info(address=0x83CE_0000, offset=0x28)

    service_0_ocb: Info = Info(address=0x83CE_0000, offset=0x30)
    service_1_ocb: Info = Info(address=0x83CE_0000, offset=0x2C)
    service_2_ocb: Info = Info(address=0x83CE_0000, offset=0x38)
    service_3_ocb: Info = Info(address=0x83CE_0000, offset=0x34)
    service_5v_ocb: Info = Info(address=0x83CE_0000, offset=0x3C)

    def get(self, name: str) -> Info:
        return getattr(self, name)


class OcbThresholds(BaseModel):
    link_0_ocb: float = 1.7
    link_1_ocb: float = 1.7
    service_0_ocb: float = 2.7
    service_1_ocb: float = 2.7
    service_2_ocb: float = 2.7
    service_3_ocb: float = 2.7
    service_5v_ocb: float = 2.7

    def get(self, name: str) -> float:
        return getattr(self, name)

    def set(self, name: str, value: float):
        return setattr(self, name, value)


class OcbThresholdsInfo(BaseModel):
    class Info(BaseModel):
        address: int = 0x0000_0000
        offset: int = 0x00

    link_0_ocb: Info = Info(address=0x83CE_0000, offset=0x04)
    link_1_ocb: Info = Info(address=0x83CE_0000, offset=0x08)

    service_0_ocb: Info = Info(address=0x83CE_0000, offset=0x10)
    service_1_ocb: Info = Info(address=0x83CE_0000, offset=0x0C)
    service_2_ocb: Info = Info(address=0x83CE_0000, offset=0x18)
    service_3_ocb: Info = Info(address=0x83CE_0000, offset=0x14)
    service_5v_ocb: Info = Info(address=0x83CE_0000, offset=0x1C)

    def get(self, name: str) -> Info:
        return getattr(self, name)
